/*
This file contains the second serial optimization.
A "continue" statement was added in order to skip unnecessary iterations
once a number that satisfies the product condition has been found.
*/

#include <stdio.h>
#include <math.h>
#include <omp.h>

int main(int argc, char *argv[]) {

    int i,j,k,l,aflag,limit,prod;
    double temp;

    if (argc<2) 
        return 0;

    limit = atoi(argv[1]);

    for (i=1;i<=limit;i++) 
    {
        aflag=0;
        for (j=i;j>=-i;j--) 
        {
            if (j==0) continue;
            for (k=i/j;k>=-i/j;k--) 
            {
		        if (k==0) continue;
                for (l=i/(j*k);l<=-i/(j*k);l++) 
                {
			        if (j*k*l == i) 
                    {
                        if (fabs((1/(double)j)+(1/(double)k)+(1/(double)l)-(1/(double)i))<1e-9) aflag=1;
                        continue;   // This skips unnecessary iterations
                                    // changing l after this will only change the
                                    // the product AWAY from i 
			        }
                }
            }
        }

        if (aflag) printf("%d\n",i);
    }
    //printf("\nOne: %u\nTwo: %u\nThree: %u\n\n", one, two, three); 
}


